package com.apobates.jforum2.troll.actionlog.entity;

import com.apobates.jforum2.troll.regular.ForumActionEnum;
import java.io.Serializable;
import java.time.LocalDateTime;
import javax.persistence.Basic;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.Table;

/**
 * 抽像的操作集合
 * 
 * @author xiaofanku
 * @since 20200514
 */
@Entity
@Table(name = "apo_action_event_set")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "TYPE", discriminatorType = DiscriminatorType.STRING, length = 20)
@DiscriminatorValue("P")
public class ActionEventDescriptor implements Serializable{
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    protected long id;
    //会员的昵称
    protected String memberNickname;
    //会员的ID
    protected long memberId;
    //动作
    @Basic
    @Enumerated(EnumType.STRING)
    protected ForumActionEnum action;
    //创建日期
    protected LocalDateTime entryDateTime;
    //IP
    protected String ipAddr;
    protected String token;
    //积分计算时的主干会员
    //有些操作(置顶)的受益会员是被操作对象的作者
    protected long rodeMember;
    
    //empty constructor for JPA instantiation
    public ActionEventDescriptor() {
        super();
    }
    
    public ActionEventDescriptor(
            String memberNickname,
            long memberId,
            ForumActionEnum action,
            LocalDateTime entryDateTime,
            String ipAddr,
            String token, 
            long rodeMember) {
        super();
        this.memberNickname = memberNickname;
        this.memberId = memberId;
        this.action = action;
        this.entryDateTime = entryDateTime;
        this.ipAddr = ipAddr;
        this.token = token;
        this.rodeMember = rodeMember;
    }
    
    public long getId() {
        return id;
    }
    
    public String getMemberNickname() {
        return memberNickname;
    }
    
    public long getMemberId() {
        return memberId;
    }
    
    public ForumActionEnum getAction() {
        return action;
    }
    
    public LocalDateTime getEntryDateTime() {
        return entryDateTime;
    }
    
    public String getIpAddr() {
        return ipAddr;
    }
    
    public String getToken() {
        return token;
    }
    
    public void setId(long id) {
        this.id = id;
    }
    
    public void setMemberNickname(String memberNickname) {
        this.memberNickname = memberNickname;
    }
    
    public void setMemberId(long memberId) {
        this.memberId = memberId;
    }
    
    public void setAction(ForumActionEnum action) {
        this.action = action;
    }
    
    public void setEntryDateTime(LocalDateTime entryDateTime) {
        this.entryDateTime = entryDateTime;
    }
    
    public void setIpAddr(String ipAddr) {
        this.ipAddr = ipAddr;
    }
    
    public void setToken(String token) {
        this.token = token;
    }
    //
    public long getRodeMember() {
        return rodeMember;
    }
    public void setRodeMember(long rodeMember) {
        this.rodeMember = rodeMember;
    }
    
    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((action == null) ? 0 : action.hashCode());
        result = prime * result + ((entryDateTime == null) ? 0 : entryDateTime.hashCode());
        result = prime * result + (int) (memberId ^ (memberId >>> 32));
        return result;
    }
    
    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        ActionEventDescriptor other = (ActionEventDescriptor) obj;
        if (action != other.action) {
            return false;
        }
        if (entryDateTime == null) {
            if (other.entryDateTime != null) {
                return false;
            }
        } else if (!entryDateTime.equals(other.entryDateTime)) {
            return false;
        }
        return memberId == other.memberId;
    }
}